package com.wehealth.electrocardiograph_two_client.activity

import com.alibaba.android.arouter.facade.annotation.Route
 import com.wehealth.electrocardiograph_two_client.R
import com.wehealth.electrocardiograph_two_client.databinding.ActivitySettingBinding
import com.wehealth.electrocardiograph_two_client.presenter.SettingPresenter
import com.wehealth.electrocardiograph_two_client.utils.FileUtils
import com.wehealth.three.lib_common.route.RouteFlag
import com.wehealth.three.lib_common.ui.component.BaseActivity
import com.wehealth.three.lib_common.utils.ResUtlis
import com.wehealth.three.lib_common.utils.SPUtil
import com.wehealth.three.lib_connect.constant.ConstantKey
import com.wehealth.three.lib_connect.constant.ConstantKey.adb_command_dir
import com.wehealth.three.lib_connect.constant.ConstantKey.adb_command_typec

@Route(path = RouteFlag.setting_page)
class SettingActivity :
    BaseActivity<ActivitySettingBinding>(
        barColor = ResUtlis.getColor(R.color.title_back_color),
        darkContent = false,
        translucent = false
    ) {
    lateinit var presenter: SettingPresenter
    override fun getLayoutId(): Int {
        return R.layout.activity_setting
    }

    override fun initData() {
        presenter = SettingPresenter(SettingActivity@ this)
        dataBinding.settingPresenter = presenter
        presenter.saveTestTypeState(dataBinding)
        presenter.saveSearchTypeState(dataBinding)
    }

    override fun onResume() {
        super.onResume()
        fixDefaultStatus()
    }

    private fun fixDefaultStatus() {
        when {
            SPUtil.getBoolean(ConstantKey.SETTING_IS_PLAY_VIDEO_KEY, true) -> {
                dataBinding.settingIsPlayVideo.isChecked = true

            }

            !SPUtil.getBoolean(ConstantKey.SETTING_IS_PLAY_VIDEO_KEY, true) -> {
                dataBinding.settingIsPlayVideo.isChecked = false

            }
        }
        when {
            SPUtil.getBoolean(ConstantKey.SETTING_IS_PACE_KEY, false) -> {
                dataBinding.settingIsPacing.isChecked = true

            }

            !SPUtil.getBoolean(ConstantKey.SETTING_IS_PACE_KEY, false) -> {
                dataBinding.settingIsPacing.isChecked = false

            }
        }


    }

    override fun onDestroy() {
        super.onDestroy()
        FileUtils.writeContentToFile(adb_command_dir, adb_command_typec.toCharArray())

    }
}